#!/bin/bash
which black 2>&1 >/dev/null
if [ $? -ne 0 ]; then
  echo 'black not found' >/dev/stderr
  exit 1
fi
which isort 2>&1 >/dev/null
if [ $? -ne 0 ]; then
  echo 'isort not found' >/dev/stderr
  exit 1
fi
if [ "$#" -eq 0 ]; then
  exec black -q --line-length=80 -S - | isort -
else
  for f in "$@"; do
    dest=$(mktemp)
    cat "$f" | black -q --line-length=80 -S - | isort - > "$dest"
    mv "$dest" "$f"
  done
fi
